class EventTarget {

    constructor() {
        this.listeners = {};
    }


    addEventListener(type, listener) {


        if (listeners[type] === undefined) {
            listeners[type] = [];
        }

        if (listeners[type].indexOf(listener) === -1) {
            listeners[type].push(listener);
        }

    }

    dispatchEvent(event) {
        for (let listener in listeners[event.type]) {
            listeners[event.type][listener](event);
        }
    }

    removeEventListener(type, listener) {
        let index = listeners[type].indexOf(listener);
        if (index !== -1) {
            listeners[type].splice(index, 1);
        }
    }

}

module.exports = EventTarget;
